package com.java_exam.java_exam.config;

import com.java_exam.java_exam.component.LoginHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class ControllerConfig implements WebMvcConfigurer {

    @Override  //自定义跳转
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("index").setViewName("index");
        registry.addViewController("/loginin.html").setViewName("loginin");

    }

    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //导入我们写好的拦截器，拦截一切内容，除去"/","/index","/loginin"三个请求
        registry.addInterceptor(new LoginHandler()).addPathPatterns("/**").excludePathPatterns("/","/index","/loginin");
    }

}
